import logging
#输出到文件
# logging.basicConfig(
#     format='%(asctime)s-%(name)s-%(levelname)s[line:%(lineno)d]-%(module)s :%(message)s',
#     datefmt='%Y-%m-%d %H:%M:%S %p',
#     filename='tmp.log',
#     level=logging.DEBUG
# )
# logging.warning('warning message test2')
# logging.error('error message test2')
# logging.critical('critical message test2')
# logging.warning('warning message test2')
# logging.error('error message test2')
# logging.critical('critical message test2')

# 要记住的
# --------------------------------------------------------------------------------------------------
# 同时向文件和屏幕上输出 和 乱码
fh=logging.FileHandler('tmp.log',encoding='utf-8')
sh=logging.StreamHandler()
fh2=logging.FileHandler('tmp2.log',encoding='utf-8')
logging.basicConfig(
    format='%(asctime)s-%(name)s-%(levelname)s[line:%(lineno)d]-%(module)s :%(message)s',
    datefmt='%Y-%m-%d %H:%M:%S %p',
    level=logging.DEBUG,
    handlers=[fh,sh,fh2]
)
logging.debug('debug 信息错误 test2')
logging.info('warning 信息错误 test2')
logging.warning('warning message test2')
logging.error('error message test2')
logging.critical('critical message test2')




























# fh = logging.FileHandler('tmp.log',encoding='utf-8')
# # fh2 = logging.FileHandler('tmp2.log',encoding='utf-8')
# sh = logging.StreamHandler()
# logging.basicConfig(
#     format='%(asctime)s - %(name)s - %(levelname)s[line :%(lineno)d]-%(module)s:  %(message)s',
#     datefmt='%Y-%m-%d %H:%M:%S %p',
#     level= logging.DEBUG,
#     # handlers=[fh,sh,fh2]
#     handlers=[fh,sh]
# )
# logging.debug('debug 信息错误 test2')
# logging.info('warning 信息错误 test2')
# logging.warning('warning message test2')
# logging.error('error message test2')
# logging.critical('critical message test2')